package lambdademo;

import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * @Author 12629
 * @Description：
 */









//无返回值无参数
@FunctionalInterface
interface NoParameterNoReturn {
    void test();
}
//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}

//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}

//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}
//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}

//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}

class Demo {
    void func() {
        System.out.println("fafasfa");
    }
}

public class Test {


    public int data1;

    class Inner {
        public static final int a = 10;
    }


    public static void func(int a,int b,int c) {

    }

    public static void func(int a,int b,int c,int d) {

    }

/*
    public static void func(int[] array) {

    }
*/


    public static void func(int... array) {
        int ret = 0;
        for (int i = 0; i < array.length; i++) {
            ret+=array[i];
        }
        System.out.println(ret);
    }


    public static void func2(int[] array) {
        array = new int[10];
    }
    public static void func3(int[] array) {
        array[0] = 9;
    }
    public static void main(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        func2(array);
        func3(array);
    }


    public static void main14(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        func(array);
        func(1,2,3,4,5,6,7);
        func(1,2,3,4,5,6,7,8,9);
        func(1,2,3,4,5,6,7,8,9,10,11,12,13);
    }

    public static void main11(String[] args) {
        int a = 10;
        double d = 19.9;
        a += d;
    }

    public static void main10(String[] args) {
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1, "hello");
        map.put(2, "bit");
        map.put(3, "hello");
        map.put(4, "lambda");

       /* map.forEach(new BiConsumer<Integer, String>() {
            @Override
            public void accept(Integer integer, String s) {
                System.out.println("key："+integer+" val: "+s);
            }
        });*/

        map.forEach((x,y)-> System.out.println("key："+x+" val: "+y));

    }


    public static void main9(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("fello");
        list.add("bit");
        list.add("hello");
        list.add("lambda");
       /* list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });*/
        list.forEach(s-> System.out.println(s));

       /* list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });
*/
        System.out.println("=====================");
        list.sort((o1, o2) -> o1.compareTo(o2));

        list.forEach(s-> System.out.println(s));

    }

    public static void main8(String[] args) {
        int size = 10;
        MoreParameterNoReturn moreParameterNoReturn = (int a,int b) -> {
            System.out.println(a+b);
            //size = 99;
            System.out.println(size);
        };
    }

    public static void main7(String[] args) {
        int a = 10;
        //a = 999;
        new Demo(){
            @Override
            void func() {
                //a = 99;
                int c = 99;
                c = 100;
                System.out.println(c+"重写一下！"+a);
            }
        }.func();

    }

    public static void main6(String[] args) {
        MoreParameterReturn moreParameterReturn = (x,y) -> x+y;
        System.out.println(moreParameterReturn.test(1, 2));
    }

    public static void main5(String[] args) {
        OneParameterReturn oneParameterReturn = x -> 2*x;
        System.out.println(oneParameterReturn.test(10));
    }

    public static void main4(String[] args) {
        NoParameterReturn noParameterReturn = () -> {return 10;};
        int ret = noParameterReturn.test();
        System.out.println(ret);

        NoParameterReturn noParameterReturn2 = () -> 10;
        int ret2 = noParameterReturn2.test();
        System.out.println(ret2);
    }

    public static void main3(String[] args) {
        MoreParameterNoReturn moreParameterNoReturn = (int a,int b) -> {
            System.out.println(a+b);
        };
        moreParameterNoReturn.test(10,20);

        MoreParameterNoReturn moreParameterNoReturn2 = ( a, b) -> System.out.println(a+b);
        moreParameterNoReturn2.test(10,20);

    }

    public static void main2(String[] args) {
        OneParameterNoReturn oneParameterNoReturn = (int x) -> {
            System.out.println(x);
        };
        oneParameterNoReturn.test(100);
        System.out.println("简化:");
        OneParameterNoReturn oneParameterNoReturn2 = x -> System.out.println(x);

        //方法引用
        OneParameterNoReturn oneParameterNoReturn3 = System.out::println;
        oneParameterNoReturn3.test(10);
    }

    public static void main1(String[] args) {

        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("测试一下！");
            }
        };

        noParameterNoReturn.test();

        NoParameterNoReturn noParameterNoReturn2 = () -> System.out.println("测试1下！");
        noParameterNoReturn2.test();

        NoParameterNoReturn noParameterNoReturn3 = () -> {
            System.out.println("测试1下！");
            System.out.println("测试2下！");
        };
        noParameterNoReturn3.test();
    }
}
